__author__ = 'liuyi'

import os
import sys

import getopt
import codecs
import binarize
import cPickle

from operator import itemgetter

sys.setdefaultencoding('utf-8')


if __name__ == '__main__':
    import sys
    import config

    try:
        opts, args = getopt.getopt(sys.argv[1:], "p:w:o:")
    except getopt.GetoptError:
        print "\nUsage: ops2tree.py [-w word][-p pos][-o operator]\n"
        sys.exit(1)

    wordFile = None
    posFile = None
    opFile = None

    for opt in opts:
        if opt[0] == '-w':
            wordFile = opt[1]
        if opt[0] == '-o':
            opFile = opt[1]
        if opt[0] == '-p':
            posFile = opt[1]

    if wordFile == None or posFile == None or opFile == None:
        print "\nUsage: ops2tree.py [-w word][-p pos][-o operator]\n"
        sys.exit(1)

    wordf = codecs.open(wordFile, encoding='utf-8')
    opf = codecs.open(opFile, encoding='utf-8')
    posf = codecs.open(posFile, encoding='utf-8')

    tree = []

    for line in zip(wordf, opf, posf):
        znode = binarize.CBinarizedTreeNode()
        print znode.ops2tree(line[1].strip().split(' '), line[0].strip().split(' '), line[2].strip().split(' '))
